import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:hotfil_pub_web/lang/translation_service.dart';
import 'package:hotfil_pub_web/pages/dashboard/dashboard_page.dart';
import 'package:hotfil_pub_web/routes/app_pages.dart';
import 'package:hotfil_pub_web/shared/http/http.dart';
import 'package:hotfil_pub_web/shared/sputils.dart';
import 'package:hotfil_pub_web/widgets/my_theme.dart';

import 'pages/home/my_home_page.dart';
import 'package:get/get.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

void main() async {
  await initStore();
  runApp(const MyApp());
  configLoading();
}

void configLoading() {
  EasyLoading.instance
    ..displayDuration = const Duration(milliseconds: 2000)
    ..indicatorType = EasyLoadingIndicatorType.fadingCircle
    ..loadingStyle = EasyLoadingStyle.dark
    ..indicatorSize = 45.0
    ..radius = 10.0
    ..progressColor = Colors.yellow
    ..backgroundColor = Colors.green
    ..indicatorColor = Colors.yellow
    ..textColor = Colors.yellow
    ..maskColor = Colors.blue.withOpacity(0.5)
    ..userInteractions = true
    ..dismissOnTap = false;
  // ..customAnimation = CustomAnimation();
}

Future<void> initStore() async {
  // 初始化本地存储类
  WidgetsFlutterBinding.ensureInitialized();
  await SpUtil.init();
  Https().init(
      baseUrl: kIsWeb ? '/api-v1' : 'https://api.hotfiltest.com/v1',
      connectTimeout: 30 * 1000,
      receiveTimeout: 30 * 1000);
  // 初始化request类

  //
  // 历史记录，全局 getx全局注入，
  // await Get.putAsync(() => HistoryService().init());
  print("全局注入");
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      themeMode: ThemeMode.light,
      theme: MyTheme.lightThemeData,
      initialRoute: SpUtil().getStr('token') == null
          ? Routes.PASS_LOGIN
          : AppPages.INITIAL,
      getPages: AppPages.routes,
      translations: TranslationService(),
      locale: TranslationService.locale,
      fallbackLocale: TranslationService.fallbackLocale,
      builder: EasyLoading.init(),
      navigatorObservers: [],
    );
  }
}
